<!-- 面试安排 -->
<script>
import bus from "@/eventBus";
import InterviewDetailLeftNav from "@/components/detailCommons/interviewDetailLeftNav";
import InterviewDetailCandidate from "@/components/detailCommons/interviewDetailCandidate";
//import InterviewDetailDemand from './../components/detailCommons/interviewDetailDemand'
import InterviewDetailDemand from "@/components/DemandDetail";
import InterviewDetailChat from "@/components/detailCommons/interviewDetailChat";
import InterviewDetailArrangeInp from "@/components/detailCommons/interviewDetailArrangeInp";
import interviewDetailArrangeCancel from "@/components/detailCommons/interviewDetailArrangeCancel";
import InterviewCourse from "@/components/interviewCourses/interviewCourse";
import InterviewTimeCourse from "@/components/interviewCourses/InterviewTimeCourse";
import { decCourses } from "@/decs/dec_interviewCourse";
import { dec_demandDetail } from "@/decs/dec_interviewDemandDetail";
import { getByteLen } from "@/utils/strLength";
function fetchArrangeDetailInfo(store, opts) {
  return store.dispatch("FETCH_ARRANGE_DETAIL", opts);
}
export default {
  components: {
    InterviewDetailCandidate,
    InterviewDetailLeftNav,
    InterviewDetailChat,
    InterviewDetailArrangeInp,
    interviewDetailArrangeCancel,
    InterviewCourse,
    InterviewTimeCourse,
    InterviewDetailDemand,
  },
  data() {
    return {
      isToBeArr: false,
      isCancel: false,
      userInfo: {
        name: "",
        ex: "",
        fileUrl: "",
        zz: "",
      },
      isCloseNeeds: "",
      interviewId: "",
      needsCvId: "",
      navs: [
        {
          lable: "简历进展概况",
          id: "2",
          val: "fill-in",
          isActive: true,
        },
        {
          lable: "候选人信息",
          id: "2",
          val: "candidate",
          isActive: false,
        },
        {
          lable: "需求详情",
          id: "3",
          val: "demand",
          isActive: false,
        },
        {
          lable: "面试时间进程",
          id: "4",
          val: "interview-time",
          isActive: false,
        },
      ],
      chartData: {
        GYInfo: {},
        DDInfo: {},
      },
      nominateInfo: {
        name: "",
        phone: "",
        email: "",
        companyName: "",
      },
      candidateData: {
        name: "",
        record: "",
        handsOn: "",
        isInJob: "",
        comeTime: "",
        phone: "",
        desc: "",
      },
      demandData: {
        jobName: "",
        jobType: "",
        moenyType: "",
        reportsTo: "",
        quantity: "",
        workingDeadline: "",
        workYears: "",
        jobAddress: "",
        budget: "",
        supplier: "",
        inJobTime: "",
        publishTime: "",
        jobDesc: "",
        jobAsk: "",
        needsCode: "",
        pathO: "",
        pathT: "",
        pathS: "",
        needsNumber: "",
      },
      courseInfos: [], // 简历历程
    };
  },
  beforeMount() {
    let id = this.$route.params.id;
    this.needId = id;
    this.state = this.$route.query.stus;
    console.log(this.$route.query.cancel)
    if (this.state && this.state == 1) {
      // 待安排
      this.isToBeArr = true;
    } else {
      this.isToBeArr = false;
    }
    if(this.$route.query.cancel) this.isCancel = true
    fetchArrangeDetailInfo(this.$store, { needsId: this.needId }).then(() => {
      let tempObj = this.$store.getters.getArrangeDetailInfo;
      if (tempObj.state === "0000") {
        let tempData = tempObj.data;
        let {
            cvdbInfo,
            referrerInfo,
            needsDetails,
            interviewArrange,
            depts,
          } = tempData,
          courseInfo = tempData.cvdbCourse;

        if (referrerInfo) {
          let strLength = getByteLen(referrerInfo.supplierName);
          let tempStr = "";
          if (strLength > 16) {
            tempStr = referrerInfo.supplierName.substr(0, 12) + "...";
          } else {
            tempStr = referrerInfo.supplierName;
          }
          this.nominateInfo = {
            name: referrerInfo.uploader_name,
            phone: referrerInfo.uploader_mobile,
            email: referrerInfo.uploader_email,
            companyName: tempStr,
            tempCompayName: referrerInfo.supplierName,
          };
        }

        // 候选人简历信息
        this.candidateData = {
          name: cvdbInfo.surname,
          record: cvdbInfo.education_code,
          handsOn: cvdbInfo.work_experience,
          isInJob: cvdbInfo.current_status_code,
          comeTime: cvdbInfo.post_time,
          phone: cvdbInfo.telephone,
          desc: cvdbInfo.reason,
        };
        this.needsCvId = cvdbInfo.needsCvId;

        // 需求详情
        this.demandData = dec_demandDetail(needsDetails, "", "", "", depts);

        this.isCloseNeeds = needsDetails.state === 6;
        if (interviewArrange) {
          this.interviewId = interviewArrange.interviewId + "";
          let tempGYInfo = {
            chatTime: interviewArrange.SUpdate_date,
            interTime: interviewArrange.DInterview_time,
            desc: interviewArrange.SBack_remark,
          };
          let tempStr = "";
          let tempStrs = [];
          if (
            interviewArrange.DInterview_time &&
            interviewArrange.DInterview_time.indexOf(",") != -1
          ) {
            tempStrs = interviewArrange.DInterview_time.split(",");
          } else {
            tempStr = interviewArrange.DInterview_time;
          }
          let tempDDInfo = {
            chatTime: interviewArrange.DUpdate_date, // 聊天更新时间
            interTime: tempGYInfo.interTime, // 面试时间
            interTime1: tempStrs[1] || "", // 面试时间
            interTime2: tempStrs[2] || "", // 面试时间
            desc: interviewArrange.DRemarks, // 备注
            format: interviewArrange.DInterview_format, // 面试形式
            addr: interviewArrange.DAddress, // 面试地点
            interviewName: interviewArrange.DInterviewName, // 面试官
            interviewPhone: interviewArrange.DInterviewMobile, // 面试官电话
          };
          this.chartData = {
            GYInfo: tempGYInfo,
            DDInfo: tempDDInfo,
          };
        }
        // 候选人信息
        this.userInfo.name = this.candidateData.name;
        this.userInfo.ex = this.demandData.postCode;
        this.userInfo.zz = cvdbInfo.file_url;
        this.userInfo.fileName = cvdbInfo.fileName;
        this.userInfo.cvdbId = cvdbInfo.id; // 文件路径ID
        // 简历进展历程
        this.courseInfos = decCourses(courseInfo);
      }
    });
  },
  mounted() {
    bus.$on("select-tab", this.selectTabItem);
  },
  methods: {
    selectTabItem(type) {
      _j("[mode-type=" + type + "]")
        .siblings(".module-box")
        .removeClass("is-active-tab");
      _j("[mode-type=" + type + "]").addClass("is-active-tab");
    },
  },
  beforeDestroy() {
    bus.$off("select-tab", this.selectTabItem);
  },
};
</script>

<template>
  <ul class="interview-common-detail arrange-detail-container">
    <li class="resume-detail-left">
      <InterviewDetailLeftNav
        :userInfo="userInfo"
        :navs="navs"
        :nominateInfo="nominateInfo"
      ></InterviewDetailLeftNav>
    </li>
    <li class="resume-detail-right">
      <backButton :backPath="'/arrange'"></backButton>
      <div v-if="isToBeArr && !isCancel && ![1, 2].includes($route.query.closeState - 0)">
        <InterviewDetailArrangeInp
          :interview-id="interviewId"
          :interview-time="chartData.DDInfo.interTime"
          :needs-cv-id="needsCvId"
          :interview-type="chartData.DDInfo.format"
          :is-close-needs="isCloseNeeds"
        ></InterviewDetailArrangeInp>
      </div>
      <div v-if="isCancel && ![1, 2].includes($route.query.closeState - 0)">
        <interviewDetailArrangeCancel
          :interview-id="interviewId"
          :interview-time="chartData.DDInfo.interTime"
          :needs-cv-id="needsCvId"
          :interview-type="chartData.DDInfo.format"
          :is-close-needs="isCloseNeeds"
        ></interviewDetailArrangeCancel>
      </div>
      <div class="module-box is-active-tab" v-bind:mode-type="'fill-in'">
        <interview-course :course-infos="courseInfos"></interview-course>
      </div>
      <div class="module-box" v-bind:mode-type="'interview-time'">
        <interview-time-course :course-infos="courseInfos"></interview-time-course>
      </div>
      <div class="module-box" v-bind:mode-type="'candidate'">
        <interview-detail-candidate
          :candidateInfo="candidateData"
        ></interview-detail-candidate>
      </div>
      <div class="module-box" v-bind:mode-type="'demand'">
        <interview-detail-demand
          :textDatas="demandData"
          :isShowInterviewBox="false"
        ></interview-detail-demand>
      </div>
    </li>
  </ul>
</template>
<style lang="scss">
@import "~@/assets/scss/mixins.scss";
@include Interview-detail;
</style>
